home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / drivers / pipedrm.c < prev    next >
C/C++ Source or Header  |  2000-05-21  |  25KB  |  833 lines

  1. /***************************************************************************
  2.  
  3.     Pipe Dream
  4.  
  5.     driver by Bryan McPhail & Aaron Giles
  6.  
  7. ****************************************************************************
  8.  
  9.     Memory map
  10.  
  11. ****************************************************************************
  12.  
  13.     ========================================================================
  14.     MAIN CPU
  15.     ========================================================================
  16.     0000-7FFF   R     xxxxxxxx   Program ROM
  17.     8000-9FFF   R/W   xxxxxxxx   Program RAM
  18.     A000-BFFF   R     xxxxxxxx   Banked ROM
  19.     C000-CBFF   R/W   xxxxxxxx   Palette RAM (1536 entries x 2 bytes)
  20.                 R/W   ---xxxxx      (0: Blue)
  21.                 R/W   xxx-----      (0: Green, 3 LSB)
  22.                 R/W   ------xx      (1: Green, 2 MSB)
  23.                 R/W   -xxxxx--      (1: Red)
  24.     CC00-CFFF   R/W   xxxxxxxx   Sprite RAM (256 entries x 8 bytes)
  25.                 R/W   xxxxxxxx      (0: Y position, 8 LSB)
  26.                 R/W   -------x      (1: Y position, 1 MSB)
  27.                 R/W   xxxx----      (1: Y zoom factor)
  28.                 R/W   xxxxxxxx      (2: X position, 8 LSB)
  29.                 R/W   -------x      (3: X position, 1 MSB)
  30.                 R/W   xxxx----      (3: X zoom factor)
  31.                 R/W   ---x----      (4: Priority)
  32.                 R/W   ----xxxx      (4: Palette entry)
  33.                 R/W   x-------      (5: Y flip)
  34.                 R/W   -xxx----      (5: Number of Y tiles - 1)
  35.                 R/W   ----x---      (5: X flip)
  36.                 R/W   -----xxx      (5: Number of X tiles - 1)
  37.                 R/W   xxxxxxxx      (6: Starting tile index, 8 LSB)
  38.                 R/W   ----xxxx      (7: Starting tile index, 4 MSB)
  39.     D000-DFFF   R/W   --xxxxxx   Background tile color
  40.     E000-EFFF   R/W   xxxxxxxx   Background tile index, 8 MSB
  41.     F000-FFFF   R/W   xxxxxxxx   Background tile index, 8 LSB
  42.     ========================================================================
  43.     0020        R     xxxxxxxx   Player 1 controls
  44.                 R     --x-----      (Fast button)
  45.                 R     ---x----      (Place button)
  46.                 R     ----xxxx      (Joystick RLDU)
  47.     0020          W   xxxxxxxx   Sound command
  48.     0021        R     xxxxxxxx   Player 2 controls
  49.                 R     --x-----      (Fast button)
  50.                 R     ---x----      (Place button)
  51.                 R     ----xxxx      (Joystick RLDU)
  52.     0021          W   -xxxxxxx   Bankswitch/video control
  53.                   W   -x------      (Flip screen)
  54.                   W   --x-----      (Background 2 X scroll, 1 MSB)
  55.                   W   ---x----      (Background 1 X scroll, 1 MSB)
  56.                   W   ----x---      (Background videoram select)
  57.                   W   -----xxx      (Bank ROM select)
  58.     0022        R     xxxxxxxx   Coinage DIP switch
  59.                 R     xxxx----      (Coin B)
  60.                 R     ----xxxx      (Coin A)
  61.     0022          W   xxxxxxxx   Background 1 X scroll, 8 LSB
  62.     0023        R     xxxxxxxx   Game options DIP switch
  63.                 R     x-------      (Test switch)
  64.                 R     -x------      (Training mode enable)
  65.                 R     --x-----      (Flip screen)
  66.                 R     ---x----      (Demo sounds)
  67.                 R     ----xx--      (Lives)
  68.                 R     ------xx      (Difficulty)
  69.     0023          W   xxxxxxxx   Background 1 Y scroll
  70.     0024        R     -x--xxxx   Coinage/start
  71.                 R     -x------      (Service coin)
  72.                 R     ----x---      (2 player start)
  73.                 R     -----x--      (1 player start)
  74.                 R     ------x-      (Coin B)
  75.                 R     -------x      (Coin A)
  76.     0024          W   xxxxxxxx   Background 2 X scroll, 8 LSB
  77.     0025        R     -------x   Sound command pending
  78.     0025          W   xxxxxxxx   Background 2 Y scroll
  79.     ========================================================================
  80.     Interrupts:
  81.        INT generated by CRTC VBLANK
  82.     ========================================================================
  83.  
  84.  
  85.     ========================================================================
  86.     SOUND CPU
  87.     ========================================================================
  88.     0000-77FF   R     xxxxxxxx   Program ROM
  89.     7800-7FFF   R/W   xxxxxxxx   Program RAM
  90.     8000-FFFF   R     xxxxxxxx   Banked ROM
  91.     ========================================================================
  92.     0004          W   -------x   Bank ROM select
  93.     0016        R     xxxxxxxx   Sound command read
  94.     0017          W   --------   Sound command acknowledge
  95.     0018-0019   R/W   xxxxxxxx   YM2610 port A
  96.     001A-001B   R/W   xxxxxxxx   YM2610 port B
  97.     ========================================================================
  98.     Interrupts:
  99.        INT generated by YM2610
  100.        NMI generated by command from main CPU
  101.     ========================================================================
  102.  
  103. ***************************************************************************/
  104.  
  105.  
  106. #include "driver.h"
  107. #include "cpu/z80/z80.h"
  108. #include "vidhrdw/generic.h"
  109. #include <math.h>
  110.  
  111.  
  112. UINT8 pipedrm_video_control;
  113.  
  114. static UINT8 pending_command;
  115. static UINT8 sound_command;
  116.  
  117.  
  118. /* video driver data & functions */
  119. int pipedrm_vh_start(void);
  120. void pipedrm_vh_stop(void);
  121. void pipedrm_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh);
  122. void hatris_vh_screenrefresh(struct osd_bitmap *bitmap, int full_refresh);
  123.  
  124.  
  125. READ_HANDLER( pipedrm_videoram_r );
  126. WRITE_HANDLER( pipedrm_videoram_w );
  127. WRITE_HANDLER( pipedrm_scroll_regs_w );
  128.  
  129. READ_HANDLER( hatris_videoram_r );
  130. WRITE_HANDLER( hatris_videoram_w );
  131.  
  132.  
  133.  
  134. /*************************************
  135.  *
  136.  *    Initialization & bankswitching
  137.  *
  138.  *************************************/
  139.  
  140. static void init_machine(void)
  141. {
  142.     UINT8 *ram;
  143.  
  144.     ram = memory_region(REGION_CPU1);
  145.     cpu_setbank(1, &ram[0x10000]);
  146.  
  147.     ram = memory_region(REGION_CPU2);
  148.     cpu_setbank(2, &ram[0x10000]);
  149. }
  150.  
  151.  
  152. static WRITE_HANDLER( pipedrm_bankswitch_w )
  153. {
  154.     /*
  155.         Bit layout:
  156.  
  157.         D7 = unknown
  158.         D6 = flip screen
  159.         D5 = background 2 X scroll MSB
  160.         D4 = background 1 X scroll MSB
  161.         D3 = background videoram select
  162.         D2-D0 = program ROM bank select
  163.     */
  164.     UINT8 *ram = memory_region(REGION_CPU1);
  165.  
  166.     /* set the memory bank on the Z80 using the low 3 bits */
  167.     cpu_setbank(1, &ram[0x10000 + (data & 0x7) * 0x2000]);
  168.  
  169.     /* save this globally because the remaining bits affect the video */
  170.     pipedrm_video_control = data;
  171. }
  172.  
  173.  
  174. static WRITE_HANDLER( sound_bankswitch_w )
  175. {
  176.     UINT8 *ram = memory_region(REGION_CPU2);
  177.     cpu_setbank(2, &ram[0x10000 + (data & 0x01) * 0x8000]);
  178. }
  179.  
  180.  
  181.  
  182. /*************************************
  183.  *
  184.  *    Sound CPU I/O
  185.  *
  186.  *************************************/
  187.  
  188. static void delayed_command_w(int data)
  189. {
  190.     sound_command = data & 0xff;
  191.     pending_command = 1;
  192.  
  193.     /* Hatris polls commands *and* listens to the NMI; this causes it to miss */
  194.     /* sound commands. It's possible the NMI isn't really hooked up on the YM2608 */
  195.     /* sound board. */
  196.     if (data & 0x100)
  197.         cpu_set_nmi_line(1, ASSERT_LINE);
  198. }
  199.  
  200.  
  201. static WRITE_HANDLER( sound_command_w )
  202. {
  203.     timer_set(TIME_NOW, data | 0x100, delayed_command_w);
  204. }
  205.  
  206.  
  207. static WRITE_HANDLER( sound_command_nonmi_w )
  208. {
  209.     timer_set(TIME_NOW, data, delayed_command_w);
  210. }
  211.  
  212.  
  213. static WRITE_HANDLER( pending_command_clear_w )
  214. {
  215.     pending_command = 0;
  216.     cpu_set_nmi_line(1, CLEAR_LINE);
  217. }
  218.  
  219.  
  220. static READ_HANDLER( pending_command_r )
  221. {
  222.     return pending_command;
  223. }
  224.  
  225.  
  226. static READ_HANDLER( sound_command_r )
  227. {
  228.     return sound_command;
  229. }
  230.  
  231.  
  232.  
  233. /*************************************
  234.  *
  235.  *    Main CPU memory handlers
  236.  *
  237.  *************************************/
  238.  
  239. static struct MemoryReadAddress readmem[] =
  240. {
  241.     { 0x0000, 0x7fff, MRA_ROM },
  242.     { 0x8000, 0x9fff, MRA_RAM },
  243.     { 0xa000, 0xbfff, MRA_BANK1 },
  244.     { 0xc000, 0xcbff, paletteram_r },
  245.     { 0xcc00, 0xcfff, MRA_RAM },
  246.     { 0xd000, 0xffff, pipedrm_videoram_r },
  247.     { -1 }  /* end of table */
  248. };
  249.  
  250.  
  251. static struct MemoryWriteAddress writemem[] =
  252. {
  253.     { 0x0000, 0x7fff, MWA_ROM },
  254.     { 0x8000, 0x9fff, MWA_RAM },
  255.     { 0xa000, 0xbfff, MWA_ROM },
  256.     { 0xc000, 0xcbff, paletteram_xRRRRRGGGGGBBBBB_w, &paletteram },
  257.     { 0xcc00, 0xcfff, MWA_RAM, &spriteram, &spriteram_size },
  258.     { 0xd000, 0xffff, pipedrm_videoram_w, &videoram, &videoram_size },
  259.     { -1 }  /* end of table */
  260. };
  261.  
  262.  
  263. static struct MemoryReadAddress hatris_readmem[] =
  264. {
  265.     { 0x0000, 0x7fff, MRA_ROM },
  266.     { 0x8000, 0x9fff, MRA_RAM },
  267.     { 0xa000, 0xbfff, MRA_BANK1 },
  268.     { 0xc000, 0xcfff, paletteram_r },
  269.     { 0xd000, 0xffff, hatris_videoram_r },
  270.     { -1 }  /* end of table */
  271. };
  272.  
  273.  
  274. static struct MemoryWriteAddress hatris_writemem[] =
  275. {
  276.     { 0x0000, 0x7fff, MWA_ROM },
  277.     { 0x8000, 0x9fff, MWA_RAM },
  278.     { 0xa000, 0xbfff, MWA_ROM },
  279.     { 0xc000, 0xcfff, paletteram_xRRRRRGGGGGBBBBB_w, &paletteram },
  280.     { 0xd000, 0xffff, hatris_videoram_w, &videoram, &videoram_size },
  281.     { -1 }  /* end of table */
  282. };
  283.  
  284.  
  285. static struct IOReadPort readport[] =
  286. {
  287.     { 0x20, 0x20, input_port_0_r },
  288.     { 0x21, 0x21, input_port_1_r },
  289.     { 0x22, 0x22, input_port_2_r },
  290.     { 0x23, 0x23, input_port_3_r },
  291.     { 0x24, 0x24, input_port_4_r },
  292.     { 0x25, 0x25, pending_command_r },
  293.     { -1 } /* end of table */
  294. };
  295.  
  296.  
  297. static struct IOWritePort writeport[] =
  298. {
  299.     { 0x20, 0x20, sound_command_w },
  300.     { 0x21, 0x21, pipedrm_bankswitch_w },
  301.     { 0x22, 0x25, pipedrm_scroll_regs_w },
  302.     { -1 } /* end of table */
  303. };
  304.  
  305.  
  306.  
  307. /*************************************
  308.  *
  309.  *    Sound CPU memory handlers
  310.  *
  311.  *************************************/
  312.  
  313. static struct MemoryReadAddress sound_readmem[] =
  314. {
  315.     { 0x0000, 0x77ff, MRA_ROM },
  316.     { 0x7800, 0x7fff, MRA_RAM },
  317.     { 0x8000, 0xffff, MRA_BANK2 },
  318.     { -1 }  /* end of table */
  319. };
  320.  
  321.  
  322. static struct MemoryWriteAddress sound_writemem[] =
  323. {
  324.     { 0x0000, 0x77ff, MWA_ROM },
  325.     { 0x7800, 0x7fff, MWA_RAM },
  326.     { 0x8000, 0xffff, MWA_ROM },
  327.     { -1 }  /* end of table */
  328. };
  329.  
  330.  
  331. static struct IOReadPort sound_readport[] =
  332. {
  333.     { 0x16, 0x16, sound_command_r },
  334.     { 0x18, 0x18, YM2610_status_port_0_A_r },
  335.     { 0x1a, 0x1a, YM2610_status_port_0_B_r },
  336.     { -1 }    /* end of table */
  337. };
  338.  
  339.  
  340. static struct IOWritePort sound_writeport[] =
  341. {
  342.     { 0x04, 0x04, sound_bankswitch_w },
  343.     { 0x17, 0x17, pending_command_clear_w },
  344.     { 0x18, 0x18, YM2610_control_port_0_A_w },
  345.     { 0x19, 0x19, YM2610_data_port_0_A_w },
  346.     { 0x1a, 0x1a, YM2610_control_port_0_B_w },
  347.     { 0x1b, 0x1b, YM2610_data_port_0_B_w },
  348.     { -1 }    /* end of table */
  349. };
  350.  
  351.  
  352. static struct IOReadPort hatris_sound_readport[] =
  353. {
  354.     { 0x04, 0x04, sound_command_r },
  355.     { 0x05, 0x05, pending_command_r },
  356.     { 0x08, 0x08, YM2608_status_port_0_A_r },
  357.     { 0x0a, 0x0a, YM2608_status_port_0_B_r },
  358.     { -1 }    /* end of table */
  359. };
  360.  
  361.  
  362. static struct IOWritePort hatris_sound_writeport[] =
  363. {
  364.     { 0x02, 0x02, YM2608_control_port_0_B_w },
  365.     { 0x03, 0x03, YM2608_data_port_0_B_w },
  366.     { 0x05, 0x05, pending_command_clear_w },
  367.     { 0x08, 0x08, YM2608_control_port_0_A_w },
  368.     { 0x09, 0x09, YM2608_data_port_0_A_w },
  369.     { 0x0a, 0x0a, YM2608_control_port_0_B_w },
  370.     { 0x0b, 0x0b, YM2608_data_port_0_B_w },
  371.     { -1 }    /* end of table */
  372. };
  373.  
  374.  
  375.  
  376. /*************************************
  377.  *
  378.  *    Port definitions
  379.  *
  380.  *************************************/
  381.  
  382. INPUT_PORTS_START( pipedrm )
  383.     PORT_START    /* $20 */
  384.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
  385.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
  386.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
  387.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
  388.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  389.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  390.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
  391.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  392.  
  393.     PORT_START    /* $21 */
  394.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
  395.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
  396.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
  397.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
  398.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  399.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  400.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_UNKNOWN )
  401.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  402.  
  403.     PORT_START    /* $22 */
  404.     PORT_DIPNAME( 0x0f, 0x0f, DEF_STR( Coin_A ))
  405.     PORT_DIPSETTING(    0x06, DEF_STR( 5C_1C ))
  406.     PORT_DIPSETTING(    0x07, DEF_STR( 4C_1C ))
  407.     PORT_DIPSETTING(    0x08, DEF_STR( 3C_1C ))
  408.     PORT_DIPSETTING(    0x09, DEF_STR( 2C_1C ))
  409.     PORT_DIPSETTING(    0x04, "6 Coins/4 Credits" )
  410.     PORT_DIPSETTING(    0x03, DEF_STR( 4C_3C ))
  411.     PORT_DIPSETTING(    0x0f, DEF_STR( 1C_1C ))
  412.     PORT_DIPSETTING(    0x02, "5 Coins/6 Credits" )
  413.     PORT_DIPSETTING(    0x01, DEF_STR( 4C_5C ))
  414.     PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ))
  415. //    PORT_DIPSETTING(    0x05, DEF_STR( 2C_3C ))
  416.     PORT_DIPSETTING(    0x0e, DEF_STR( 1C_2C ))
  417.     PORT_DIPSETTING(    0x0d, DEF_STR( 1C_3C ))
  418.     PORT_DIPSETTING(    0x0c, DEF_STR( 1C_4C ))
  419.     PORT_DIPSETTING(    0x0b, DEF_STR( 1C_5C ))
  420.     PORT_DIPSETTING(    0x0a, DEF_STR( 1C_6C ))
  421.     PORT_DIPNAME( 0xf0, 0xf0, DEF_STR( Coin_B ))
  422.     PORT_DIPSETTING(    0x60, DEF_STR( 5C_1C ))
  423.     PORT_DIPSETTING(    0x70, DEF_STR( 4C_1C ))
  424.     PORT_DIPSETTING(    0x80, DEF_STR( 3C_1C ))
  425.     PORT_DIPSETTING(    0x90, DEF_STR( 2C_1C ))
  426.     PORT_DIPSETTING(    0x40, "6 Coins/4 Credits" )
  427.     PORT_DIPSETTING(    0x30, DEF_STR( 4C_3C ))
  428.     PORT_DIPSETTING(    0xf0, DEF_STR( 1C_1C ))
  429.     PORT_DIPSETTING(    0x20, "5 Coins/6 Credits" )
  430.     PORT_DIPSETTING(    0x10, DEF_STR( 4C_5C ))
  431.     PORT_DIPSETTING(    0x00, DEF_STR( 2C_3C ))
  432. //    PORT_DIPSETTING(    0x50, DEF_STR( 2C_3C ))
  433.     PORT_DIPSETTING(    0xe0, DEF_STR( 1C_2C ))
  434.     PORT_DIPSETTING(    0xd0, DEF_STR( 1C_3C ))
  435.     PORT_DIPSETTING(    0xc0, DEF_STR( 1C_4C ))
  436.     PORT_DIPSETTING(    0xb0, DEF_STR( 1C_5C ))
  437.     PORT_DIPSETTING(    0xa0, DEF_STR( 1C_6C ))
  438.  
  439.     PORT_START    /* $23 */
  440.     PORT_DIPNAME( 0x03, 0x03, DEF_STR( Difficulty ))
  441.     PORT_DIPSETTING(    0x02, "Easy" )
  442.     PORT_DIPSETTING(    0x03, "Normal" )
  443.     PORT_DIPSETTING(    0x01, "Hard" )
  444.     PORT_DIPSETTING(    0x00, "Super" )
  445.     PORT_DIPNAME( 0x0c, 0x04, DEF_STR( Lives ))
  446.     PORT_DIPSETTING(    0x0c, "1" )
  447.     PORT_DIPSETTING(    0x08, "2" )
  448.     PORT_DIPSETTING(    0x04, "3" )
  449.     PORT_DIPSETTING(    0x00, "4" )
  450.     PORT_DIPNAME( 0x10, 0x10, DEF_STR( Demo_Sounds ))
  451.     PORT_DIPSETTING(    0x00, DEF_STR( Off ))
  452.     PORT_DIPSETTING(    0x10, DEF_STR( On ))
  453.     PORT_DIPNAME( 0x20, 0x20, DEF_STR( Flip_Screen ))
  454.     PORT_DIPSETTING(    0x20, DEF_STR( Off ))
  455.     PORT_DIPSETTING(    0x00, DEF_STR( On ))
  456.     PORT_DIPNAME( 0x40, 0x40, "Training Mode" )
  457.     PORT_DIPSETTING(    0x00, DEF_STR( Off ))
  458.     PORT_DIPSETTING(    0x40, DEF_STR( On ))
  459.     PORT_SERVICE( 0x80, IP_ACTIVE_LOW )
  460.  
  461.     PORT_START    /* $24 */
  462.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  463.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  464.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START1 )
  465.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START2 )
  466.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNKNOWN )
  467.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNKNOWN )
  468.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE1 )
  469.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  470. INPUT_PORTS_END
  471.  
  472.  
  473. INPUT_PORTS_START( hatris )
  474.     PORT_START    /* $20 */
  475.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER1 )
  476.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER1 )
  477.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER1 )
  478.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER1 )
  479.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER1 )
  480.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER1 )
  481.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER1 )
  482.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  483.  
  484.     PORT_START    /* $21 */
  485.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_JOYSTICK_UP    | IPF_8WAY | IPF_PLAYER2 )
  486.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_JOYSTICK_DOWN  | IPF_8WAY | IPF_PLAYER2 )
  487.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_JOYSTICK_LEFT  | IPF_8WAY | IPF_PLAYER2 )
  488.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_JOYSTICK_RIGHT | IPF_8WAY | IPF_PLAYER2 )
  489.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_BUTTON1 | IPF_PLAYER2 )
  490.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_BUTTON2 | IPF_PLAYER2 )
  491.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_BUTTON3 | IPF_PLAYER2 )
  492.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNKNOWN )
  493.  
  494.     PORT_START    /* $22 */
  495.     PORT_DIPNAME( 0x0f, 0x00, DEF_STR( Coin_A ))
  496.     PORT_DIPSETTING(    0x09, DEF_STR( 5C_1C ))
  497.     PORT_DIPSETTING(    0x08, DEF_STR( 4C_1C ))
  498.     PORT_DIPSETTING(    0x07, DEF_STR( 3C_1C ))
  499.     PORT_DIPSETTING(    0x06, DEF_STR( 2C_1C ))
  500.     PORT_DIPSETTING(    0x0b, "6 Coins/4 Credits" )
  501.     PORT_DIPSETTING(    0x0c, DEF_STR( 4C_3C ))
  502.     PORT_DIPSETTING(    0x00, DEF_STR( 1C_1C ))
  503.     PORT_DIPSETTING(    0x0d, "5 Coins/6 Credits" )
  504.     PORT_DIPSETTING(    0x0e, DEF_STR( 4C_5C ))
  505.     PORT_DIPSETTING(    0x0f, DEF_STR( 2C_3C ))
  506. //    PORT_DIPSETTING(    0x0a, DEF_STR( 2C_3C ))
  507.     PORT_DIPSETTING(    0x01, DEF_STR( 1C_2C ))
  508.     PORT_DIPSETTING(    0x02, DEF_STR( 1C_3C ))
  509.     PORT_DIPSETTING(    0x03, DEF_STR( 1C_4C ))
  510.     PORT_DIPSETTING(    0x04, DEF_STR( 1C_5C ))
  511.     PORT_DIPSETTING(    0x05, DEF_STR( 1C_6C ))
  512.     PORT_DIPNAME( 0xf0, 0x00, DEF_STR( Coin_B ))
  513.     PORT_DIPSETTING(    0x90, DEF_STR( 5C_1C ))
  514.     PORT_DIPSETTING(    0x80, DEF_STR( 4C_1C ))
  515.     PORT_DIPSETTING(    0x70, DEF_STR( 3C_1C ))
  516.     PORT_DIPSETTING(    0x60, DEF_STR( 2C_1C ))
  517.     PORT_DIPSETTING(    0xb0, "6 Coins/4 Credits" )
  518.     PORT_DIPSETTING(    0xc0, DEF_STR( 4C_3C ))
  519.     PORT_DIPSETTING(    0x00, DEF_STR( 1C_1C ))
  520.     PORT_DIPSETTING(    0xd0, "5 Coins/6 Credits" )
  521.     PORT_DIPSETTING(    0xe0, DEF_STR( 4C_5C ))
  522.     PORT_DIPSETTING(    0xf0, DEF_STR( 2C_3C ))
  523. //    PORT_DIPSETTING(    0xa0, DEF_STR( 2C_3C ))
  524.     PORT_DIPSETTING(    0x10, DEF_STR( 1C_2C ))
  525.     PORT_DIPSETTING(    0x20, DEF_STR( 1C_3C ))
  526.     PORT_DIPSETTING(    0x30, DEF_STR( 1C_4C ))
  527.     PORT_DIPSETTING(    0x40, DEF_STR( 1C_5C ))
  528.     PORT_DIPSETTING(    0x50, DEF_STR( 1C_6C ))
  529.  
  530.     PORT_START    /* $23 */
  531.     PORT_DIPNAME( 0x03, 0x00, "Difficulty 1" )
  532.     PORT_DIPSETTING(    0x01, "Easy" )
  533.     PORT_DIPSETTING(    0x00, "Normal" )
  534.     PORT_DIPSETTING(    0x02, "Hard" )
  535.     PORT_DIPSETTING(    0x03, "Super" )
  536.     PORT_DIPNAME( 0x0c, 0x00, "Difficulty 2" )
  537.     PORT_DIPSETTING(    0x04, "Easy" )
  538.     PORT_DIPSETTING(    0x00, "Normal" )
  539.     PORT_DIPSETTING(    0x08, "Hard" )
  540.     PORT_DIPSETTING(    0x0c, "Super" )
  541.     PORT_SERVICE( 0x10, IP_ACTIVE_HIGH )
  542.     PORT_DIPNAME( 0x20, 0x00, DEF_STR( Flip_Screen ))
  543.     PORT_DIPSETTING(    0x00, DEF_STR( Off ))
  544.     PORT_DIPSETTING(    0x20, DEF_STR( On ))
  545.     PORT_DIPNAME( 0x40, 0x00, DEF_STR( Demo_Sounds ))
  546.     PORT_DIPSETTING(    0x40, DEF_STR( Off ))
  547.     PORT_DIPSETTING(    0x00, DEF_STR( On ))
  548.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
  549.  
  550.     PORT_START    /* $24 */
  551.     PORT_BIT( 0x01, IP_ACTIVE_LOW, IPT_COIN1 )
  552.     PORT_BIT( 0x02, IP_ACTIVE_LOW, IPT_COIN2 )
  553.     PORT_BIT( 0x04, IP_ACTIVE_LOW, IPT_START1 )
  554.     PORT_BIT( 0x08, IP_ACTIVE_LOW, IPT_START2 )
  555.     PORT_BIT( 0x10, IP_ACTIVE_LOW, IPT_UNUSED )
  556.     PORT_BIT( 0x20, IP_ACTIVE_LOW, IPT_UNUSED )
  557.     PORT_BIT( 0x40, IP_ACTIVE_LOW, IPT_SERVICE1 )
  558.     PORT_BIT( 0x80, IP_ACTIVE_LOW, IPT_UNUSED )
  559. INPUT_PORTS_END
  560.  
  561.  
  562.  
  563. /*************************************
  564.  *
  565.  *    Graphics definitions
  566.  *
  567.  *************************************/
  568.  
  569. static struct GfxLayout bglayout =
  570. {
  571.     8,4,
  572.     RGN_FRAC(1,1),
  573.     4,
  574.     { 0, 1, 2, 3 },
  575.     { 4, 0, 12, 8, 20, 16, 28, 24 },
  576.     { 0*32, 1*32, 2*32, 3*32 },
  577.     8*16
  578. };
  579.  
  580.  
  581. static struct GfxLayout splayout =
  582. {
  583.     16,16,
  584.     RGN_FRAC(1,1),
  585.     4,
  586.     { 0, 1, 2, 3 },
  587.     { 12, 8, 28, 24, 4, 0, 20, 16, 44, 40, 60, 56, 36, 32, 52, 48 },
  588.     { 0*64, 1*64, 2*64, 3*64, 4*64, 5*64, 6*64, 7*64,
  589.             8*64, 9*64, 10*64, 11*64, 12*64, 13*64, 14*64, 15*64 },
  590.     8*128
  591. };
  592.  
  593.  
  594. static struct GfxDecodeInfo gfxdecodeinfo[] =
  595. {
  596.     { REGION_GFX1, 0, &bglayout,    0, 64 },
  597.     { REGION_GFX2, 0, &bglayout,    0, 64 },
  598.     { REGION_GFX3, 0, &splayout, 1024, 32 },
  599.     { -1 } /* end of array */
  600. };
  601.  
  602.  
  603. static struct GfxDecodeInfo gfxdecodeinfo_hatris[] =
  604. {
  605.     { REGION_GFX1, 0, &bglayout,    0, 128 },
  606.     { REGION_GFX2, 0, &bglayout,    0, 128 },
  607.     { -1 } /* end of array */
  608. };
  609.  
  610.  
  611.  
  612. /*************************************
  613.  *
  614.  *    Sound definitions
  615.  *
  616.  *************************************/
  617.  
  618. static void irqhandler(int irq)
  619. {
  620.     cpu_set_irq_line(1, 0, irq ? ASSERT_LINE : CLEAR_LINE);
  621. }
  622.  
  623.  
  624. static struct YM2608interface ym2608_interface =
  625. {
  626.     1,
  627.     8000000,    /* 8 MHz */
  628.     { 50 },
  629.     { 0 },
  630.     { 0 },
  631.     { 0 },
  632.     { 0 },
  633.     { irqhandler },
  634.     { REGION_SOUND1 },
  635.     { YM3012_VOL(50,MIXER_PAN_LEFT,50,MIXER_PAN_RIGHT) }
  636. };
  637.  
  638.  
  639. static struct YM2610interface ym2610_interface =
  640. {
  641.     1,
  642.     8000000,    /* 8 MHz */
  643.     { 50 },
  644.     { 0 },
  645.     { 0 },
  646.     { 0 },
  647.     { 0 },
  648.     { irqhandler },
  649.     { REGION_SOUND1 },
  650.     { REGION_SOUND2 },
  651.     { YM3012_VOL(50,MIXER_PAN_LEFT,50,MIXER_PAN_RIGHT) }
  652. };
  653.  
  654.  
  655.  
  656. /*************************************
  657.  *
  658.  *    Machine driver
  659.  *
  660.  *************************************/
  661.  
  662. static struct MachineDriver machine_driver_pipedrm =
  663. {
  664.     /* basic machine hardware */
  665.     {
  666.         {
  667.             CPU_Z80,
  668.             12000000/2,
  669.             readmem,writemem,readport,writeport,
  670.             interrupt,1
  671.         },
  672.         {
  673.             CPU_Z80 | CPU_AUDIO_CPU,
  674.             14318000/4,
  675.             sound_readmem,sound_writemem,sound_readport,sound_writeport,
  676.             ignore_interrupt,0
  677.         }
  678.     },
  679.     60, DEFAULT_REAL_60HZ_VBLANK_DURATION,
  680.     1,
  681.     init_machine,
  682.  
  683.     /* video hardware */
  684.       44*8, 30*8, { 0*8, 44*8-1, 0*8, 30*8-1 },
  685.     gfxdecodeinfo,
  686.     1536,1536,
  687.     0,
  688.  
  689.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  690.     0,
  691.     pipedrm_vh_start,
  692.     pipedrm_vh_stop,
  693.     pipedrm_vh_screenrefresh,
  694.  
  695.     /* sound hardware */
  696.     0,0,0,0,
  697.     {
  698.         { SOUND_YM2610, &ym2610_interface }
  699.     }
  700. };
  701.  
  702.  
  703. static struct MachineDriver machine_driver_hatris =
  704. {
  705.     /* basic machine hardware */
  706.     {
  707.         {
  708.             CPU_Z80,
  709.             12000000/2,
  710.             hatris_readmem,hatris_writemem,readport,writeport,
  711.             interrupt,1
  712.         },
  713.         {
  714.             CPU_Z80 | CPU_AUDIO_CPU,
  715.             14318000/4,
  716.             sound_readmem,sound_writemem,hatris_sound_readport,hatris_sound_writeport,
  717.             ignore_interrupt,0
  718.         }
  719.     },
  720.     60, DEFAULT_REAL_60HZ_VBLANK_DURATION,
  721.     1,
  722.     init_machine,
  723.  
  724.     /* video hardware */
  725.       44*8, 30*8, { 0*8, 44*8-1, 0*8, 30*8-1 },
  726.     gfxdecodeinfo_hatris,
  727.     2048,2048,
  728.     0,
  729.  
  730.     VIDEO_TYPE_RASTER | VIDEO_MODIFIES_PALETTE,
  731.     0,
  732.     pipedrm_vh_start,
  733.     pipedrm_vh_stop,
  734.     hatris_vh_screenrefresh,
  735.  
  736.     /* sound hardware */
  737.     0,0,0,0,
  738.     {
  739.         { SOUND_YM2608, &ym2608_interface }
  740.     }
  741. };
  742.  
  743.  
  744.  
  745. /*************************************
  746.  *
  747.  *    ROM definitions
  748.  *
  749.  *************************************/
  750.  
  751. ROM_START( pipedrm )
  752.     ROM_REGION( 0x20000, REGION_CPU1 )
  753.     ROM_LOAD( "1",    0x00000, 0x08000, 0xdbfac46b )
  754.     ROM_LOAD( "2",    0x10000, 0x10000, 0xb7adb99a )
  755.  
  756.     ROM_REGION( 0x20000, REGION_CPU2 )
  757.     ROM_LOAD( "4",    0x00000, 0x08000, 0x497fad4c )
  758.     ROM_LOAD( "3",    0x10000, 0x10000, 0x4800322a )
  759.  
  760.     ROM_REGION( 0x100000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  761.     ROM_LOAD( "s73",    0x000000, 0x80000, 0x63f4e10c )
  762.     ROM_LOAD( "s72",    0x080000, 0x80000, 0x4e669e97 )
  763.  
  764.     ROM_REGION( 0x100000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  765.     ROM_LOAD( "s71",    0x000000, 0x80000, 0x431485ee )
  766.     /* s72 will be copied here */
  767.  
  768.     ROM_REGION( 0x080000, REGION_GFX3 | REGIONFLAG_DISPOSE )
  769.     ROM_LOAD_GFX_EVEN( "a30", 0x00000, 0x40000, 0x50bc5e98 )
  770.     ROM_LOAD_GFX_ODD ( "a29", 0x00000, 0x40000, 0xa240a448 )
  771.  
  772.     ROM_REGION( 0x80000, REGION_SOUND1 )
  773.     ROM_LOAD( "g72",     0x00000, 0x80000, 0xdc3d14be )
  774.  
  775.     ROM_REGION( 0x80000, REGION_SOUND2 )
  776.     ROM_LOAD( "g71",     0x00000, 0x80000, 0x488e2fd1 )
  777. ROM_END
  778.  
  779.  
  780. ROM_START( hatris )
  781.     ROM_REGION( 0x10000, REGION_CPU1 )
  782.     ROM_LOAD( "2-ic79.bin",    0x00000, 0x08000, 0xbbcaddbf )
  783.  
  784.     ROM_REGION( 0x10000, REGION_CPU2 )
  785.     ROM_LOAD( "1-ic81.bin",    0x00000, 0x08000, 0xdb25e166 )
  786.  
  787.     ROM_REGION( 0x80000, REGION_GFX1 | REGIONFLAG_DISPOSE )
  788.     ROM_LOAD( "b0-ic56.bin", 0x00000, 0x20000, 0x34f337a4 )
  789.     ROM_LOAD( "b1-ic73.bin", 0x40000, 0x08000, 0x6351d0ba )
  790.  
  791.     ROM_REGION( 0x40000, REGION_GFX2 | REGIONFLAG_DISPOSE )
  792.     ROM_LOAD( "a0-ic55.bin", 0x00000, 0x20000, 0x7b7bc619 )
  793.     ROM_LOAD( "a1-ic60.bin", 0x20000, 0x20000, 0xf74d4168 )
  794.  
  795.     ROM_REGION( 0x20000, REGION_SOUND1 )
  796.     ROM_LOAD( "pc-ic53.bin", 0x00000, 0x20000, 0x07147712 )
  797. ROM_END
  798.  
  799.  
  800.  
  801. /*************************************
  802.  *
  803.  *    Driver initialization
  804.  *
  805.  *************************************/
  806.  
  807. static void init_pipedrm(void)
  808. {
  809.     /* copy the shared ROM from GFX1 to GFX2 */
  810.     memcpy(memory_region(REGION_GFX2) + 0x80000, memory_region(REGION_GFX1) + 0x80000, 0x80000);
  811. }
  812.  
  813.  
  814. static void init_hatris(void)
  815. {
  816.     /* clear out unused ROM regions */
  817.     memset(memory_region(REGION_GFX1) + 0x20000, 0, 0x20000);
  818.     memset(memory_region(REGION_GFX1) + 0x48000, 0, 0x38000);
  819.  
  820.     install_port_write_handler(0, 0x20, 0x20, sound_command_nonmi_w);
  821. }
  822.  
  823.  
  824.  
  825. /*************************************
  826.  *
  827.  *    Game drivers
  828.  *
  829.  *************************************/
  830.  
  831. GAME( 1990, pipedrm, 0, pipedrm, pipedrm, pipedrm, ROT0, "Video System Co.", "Pipe Dream (Japan)" )
  832. GAME( 1990, hatris,  0, hatris,  hatris,  hatris,  ROT0, "Video System Co.", "Hatris (Japan)" )
  833.